<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod">




    <ui:define name="content">

        <h:outputStylesheet library="css" name="printing.css" />

        <h:panelGroup styleClass="opdPanel" >
            <h:form id="form">

                <h:panelGroup rendered="#{!appointmentController.printPreview}" styleClass="alignTop" >
                    <p:panel style="min-height: 600px; position:relative;"  >
                        <f:facet name="header" >
                            <h:panelGrid columns="17"  >
                                <h:outputLabel value="Appointment" />
                                <h:outputLabel value="&nbsp;&nbsp;&nbsp;&nbsp;" style="min-width: 50px;" />
                                <p:selectOneMenu   id="cmbPs" value="#{appointmentController.currentBill.paymentMethod}">                                                                     
                                    <f:selectItems value="#{enumController.paymentMethodsWithoutCredit}"/>
                                    <p:ajax process="cmbPs" update="pBillDetails creditCard cheque slip" event="change" />
                                </p:selectOneMenu>

                                <h:panelGroup id="creditCard" style="display: #{appointmentController.currentBill.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                    <pa:creditCard paymentMethodData="#{appointmentController.paymentMethodData}"/>
                                </h:panelGroup>

                                <h:panelGroup id="cheque" style="display: #{appointmentController.currentBill.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                    <pa:cheque paymentMethodData="#{appointmentController.paymentMethodData}"/>
                                </h:panelGroup>

                                <h:panelGroup id="slip" style="display: #{appointmentController.currentBill.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                    <pa:slip paymentMethodData="#{appointmentController.paymentMethodData}"/>
                                </h:panelGroup>

                                <p:commandButton  value="Settle" action="#{appointmentController.settleBill}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;" onclick="onSubmitButton();">
                                </p:commandButton>
                                <p:commandButton value="New Bill" ajax="false" action="#{appointmentController.prepareNewBill()}" onclick="onSubmitButton();" >
                                </p:commandButton>
                                
                            </h:panelGrid>

                        </f:facet>

                        <h:panelGrid columns="2" >

                            <h:panelGrid columns="1" >

                                <h:panelGroup id="panelPatient" >

                                    <p:tabView id="tvPt" style="min-height: 250px;"  >
                                        <p:ajax event="tabChange"  process="@this" listener="#{appointmentController.onTabChange}" />

                                        <p:tab id="tabNewPt" title="New Patient"  >
                                            <ez:patientDetail controller="#{appointmentController}"/>
                                        </p:tab>
                                        <p:tab id="tabSearchPt" title="Search Patient">

                                            <h:panelGrid columns="1" >
                                                <p:autoComplete widgetVar="aPt" id="acPt" forceSelection="true" 
                                                                value="#{appointmentController.searchedPatient}" 
                                                                completeMethod="#{patientController.completePatient}" 
                                                                var="apt" itemLabel="#{apt.person.name}" 
                                                                itemValue="#{apt}" size="30"  style="width: 400px;" required="true" requiredMessage="please Select the Patient">
                                                    <f:ajax event="itemSelect" execute="acPt" render="panSearch"/>
                                                </p:autoComplete>
                                                
                                               

                                                <h:panelGrid id="panSearch" columns="2" >
                                                    <h:outputLabel  rendered="#{appointmentController.searchedPatient!=null}" value="Name" />
                                                    <h:outputLabel rendered="#{appointmentController.searchedPatient!=null}" value="#{appointmentController.searchedPatient.person.name}" ></h:outputLabel>
                                                    <h:outputLabel  rendered="#{appointmentController.searchedPatient!=null}" value="Sex" />
                                                    <h:outputLabel rendered="#{appointmentController.searchedPatient!=null}" value="#{appointmentController.searchedPatient.person.sex}" ></h:outputLabel>
                                                    <h:outputLabel  rendered="#{appointmentController.searchedPatient!=null}" value="DOB"  />

                                                    <h:outputLabel rendered="#{appointmentController.searchedPatient!=null}" value="#{appointmentController.searchedPatient.person.dob}"   >
                                                        <f:convertDateTime pattern="dd/MM/yy" />
                                                    </h:outputLabel>

                                                    <h:outputLabel  rendered="#{appointmentController.searchedPatient!=null}" value="Adress" />
                                                    <p:inputTextarea rendered="#{appointmentController.searchedPatient!=null}" value="#{appointmentController.searchedPatient.person.address}" />
                                                </h:panelGrid>
                                            </h:panelGrid>

                                        </p:tab>

                                    </p:tabView>

                                </h:panelGroup>


                            </h:panelGrid>


                            <h:panelGrid columns="1"  id="refferingDr">

                                <p:dialog id="panDoc" header="Add New Doctor" widgetVar="dlg" resizable="false">  
                                    <h:panelGrid columns="2" style="margin-bottom:10px">  
                                        <h:outputText id="lblNameD" value="Name" ></h:outputText>
                                        <h:inputText autocomplete="off" id="txtNameD"  value="#{doctorController.current.person.name}"  ></h:inputText>
                                        <h:outputText id="lblPhoneD" value="Phone" ></h:outputText>
                                        <h:inputText autocomplete="off" id="txtPhoneD" value="#{doctorController.current.person.phone}"  ></h:inputText>
                                        <h:outputText id="lblFaxD" value="Fax" ></h:outputText>
                                        <h:inputText autocomplete="off" id="txtFaxD" value="#{doctorController.current.person.fax}"  ></h:inputText>
                                        <h:outputText id="lblMobileD" value="Mobile" ></h:outputText>
                                        <h:inputText autocomplete="off" id="txtMobileD" value="#{doctorController.current.person.mobile}"  ></h:inputText>
                                        <h:outputText id="lblAddressD" value="Address" ></h:outputText>
                                        <h:inputText autocomplete="off" id="txtAddressD" value="#{doctorController.current.person.address}"  ></h:inputText>
                                        <h:outputText value="Speciality" ></h:outputText>                                    
                                        <h:selectOneListbox id="cmbSpecialityD" size="1" value="#{doctorController.current.speciality}" >
                                            <f:selectItem itemLabel="Please select a speciality"/>
                                            <f:selectItems value="#{specialityController.items}" var="cat" itemLabel="#{cat.name}" itemValue="#{cat}" />
                                        </h:selectOneListbox>
                                        <h:outputText id="lblRegD" value="Registration" ></h:outputText>
                                        <h:inputText autocomplete="off" id="txtRegD" value="#{doctorController.current.registration}"  ></h:inputText>                 
                                        <h:outputText id="lblQuaD" value="Qualification" ></h:outputText>
                                        <h:inputText autocomplete="off" id="txtQuaD" value="#{doctorController.current.qualification}"  ></h:inputText>   

                                        <p:commandButton id="btnDocSave" value="Add New" process="btnDocSave panDoc" update="panDoc :#{p:component('cmbDoc')}" actionListener="#{doctorController.saveSelected()}" styleClass="buttons" oncomplete="dlg.hide();" onclick="onSubmitButton();">
                                        </p:commandButton>

                                    </h:panelGrid>  

                                </p:dialog>  


                                <h:panelGroup id="panelBillReferrals" >
                                    <p:tabView >
                                        <p:tab title="Refering Doctor" id="rdr">
                                            <p:autoComplete forceSelection="true" id="cmbDoc" value="#{appointmentController.currentBill.referredBy}" completeMethod="#{doctorController.completeDoctor}" var="ix" itemLabel="#{ix.person.name}" itemValue="#{ix}" size="30"  style="width: 400px;">
                                            </p:autoComplete>
                                            <p:commandButton id="btnAddNewDoc" type="button" value="Add New Doctor" onclick="dlg.show();" actionListener="#{doctorController.prepareAdd}" process="btnAddNewDoc" update="#{p:component('panDoc')}" >
                                            <p:resetInput target="panelBillReferrals"/>
                                            </p:commandButton>  
                                      
                                        </p:tab>

                                    </p:tabView>
                                </h:panelGroup>

                                <h:panelGrid columns="2">
                                    <p:outputLabel value="Appointment Date :"/>
                                    <p:calendar  value="#{appointmentController.currentAppointment.appointmentDate}" pattern="dd MMMM yyyy">                            
                                    </p:calendar>
                                </h:panelGrid>

                                <h:panelGroup id="panelBillTotals" >

                                    <p:panel header="Bill Details" id="pBillDetails" style="padding: 5px; margin: 10px;" >
                                        <p:panelGrid columns="2" columnClasses="numberCol, textCol"  >
                                            <h:outputLabel value="Amount" ></h:outputLabel>
                                            <p:inputText autocomplete="off" value="#{appointmentController.currentBill.total}" >
                                                <f:convertNumber pattern="#,##0.00" />
                                            </p:inputText>
                                        </p:panelGrid>

                                    </p:panel>
                                </h:panelGroup>




                            </h:panelGrid>


                        </h:panelGrid>
                    </p:panel>
                </h:panelGroup>


                <h:panelGroup rendered="#{appointmentController.printPreview}" >


                </h:panelGroup>

            </h:form>
        </h:panelGroup>
    </ui:define>
</ui:composition>
